package gui.GLListeners;

import figuras.PuntoVector;

import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.glu.GLU;

import utils.UnidadesGraficas;
import camaras.Camara;

public class GLListenerVisor extends GLListener {
	
	private PuntoVector eye;
	
	private PuntoVector up;
	
	private PuntoVector look;
	
	public void setEye(PuntoVector eye) {
		this.eye = eye;
	}


	public void setUp(PuntoVector up) {
		this.up = up;
	}


	public void setLook(PuntoVector look) {
		this.look = look;
	}


	public GLListenerVisor(PuntoVector eye,PuntoVector look, PuntoVector up, 
			double xRight, double yTop) {		
		glu = new GLU();
		this.xRight = xRight;
		xLeft = -xRight;
		this.yTop = yTop;
		yBot = -xRight;
		xCentro = (xRight + xLeft) / 2.0; // =0;
		yCentro = (yTop + yBot) / 2.0; // =0;
		RatioViewPort = 1.0;
		this.look = look;
		this.eye = eye;
		this.up = up;
	}


	public void init(GLAutoDrawable glDrawable) {
		gl = glDrawable.getGL();
		gl.glClearColor(0.6f, 0.7f, 0.8f, 1.0f);
		RatioViewPort = 1.0;		
		int flag = 0;// 0 Ortogonal 1 perspectiva
		camara = new Camara(eye, look, up, flag, xLeft, xRight, yBot, yTop, 1,
				1000, 90, 0.5, gl, glu);
	}


	public void display(GLAutoDrawable glDrawable) {
		gl = glDrawable.getGL();
		gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
		gl.glMatrixMode(GL.GL_MODELVIEW);
		gl.glPointSize(1.0f);
		UnidadesGraficas.cruzetaDoble(xRight, gl);	
		if (componente!= null)
			componente.dibuja(GL.GL_LINE_LOOP);
		gl.glFlush();			
	}
	
	public void setCamara(PuntoVector eye,PuntoVector look, PuntoVector up){
		camara.vista(eye, look, up);
	}	

}
